import http from '../../utils/newrequest'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        reviewlist: [],
        count: '',
        stepbc: 1,
        flagsourceid: '',
        name: '',
        windowHeight: 0,
        scrollHeight: 0,
        page: 0,
        pageSize: 20,
        teacherId: 0,
        examId: 0,
        assignmentConfigId: 0,
        questionNumber: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // //console.info(options,'11111111111111111')
        this.setData({ teacherId: options.teacherId, examId: options.examId, assignmentConfigId: options.assignmentConfigId, questionNumber: options.questionNumber })
        // return false
        // let that = this;
        // let info = null
        // this.setData({
        //     stepbc: options.stepbc,
        //     flagsourceid: options.flagsourceid,
        //     name: options.name
        // })
        // if (wx.getStorageSync('huiqongINfo')) {
        //     info = JSON.parse(wx.getStorageSync('huiqongINfo'))
        //     this.setData({stepbc:JSON.parse(info.stepbc),flagsourceid:info.flagsourceid})
        // }
        wx.removeStorageSync('tasklist');
        this.getreviewlist()
    },
    onScrollToLower() {
        var that = this
        let { count, page } = this.data
        let pages = getCurrentPages();
        let currPage = pages[pages.length - 1];
        if (count > page * 20) {
            // let info = null
            // if (wx.getStorageSync('huiqongINfo')) {
            //     info = JSON.parse(wx.getStorageSync('huiqongINfo'))
            // }
            this.getreviewlist()
        } else {
            wx.showToast({
                title: '到底啦!',
                icon: "none"
            })
        }
    },
    // 获取回评列表 getMyTasklist
    async getreviewlist() {
        let that = this
        if (wx.getStorageSync('newtoken')) {
            let id = JSON.parse(wx.getStorageSync('newtoken')).id
            this.setData({
                page: this.data.page + 1
            })
            let { page, teacherId, examId, assignmentConfigId } = this.data
            let options = {
                url: '/task/teacher/assignment/rebackList',
                method: 'get',
                data: { pageNum: page, pageSize: 20, teacherId: teacherId, examId: examId, assignmentConfigId: assignmentConfigId },
                header: { "content-type": "application/json;charset=UTF-8" }
            }
            let res = await http(options)
            //console.info(res)
            // return false 
            if (res.data.code == 200) {
                this.setData({ reviewlist: [...this.data.reviewlist, ...res.data.rows], count: res.data.total })
                wx.setStorageSync('reviewlist', JSON.stringify(res.data.rows))
                // this.getScrollHeights()
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/teacherlogin/teacherlogin',
            })
        }
    },
    goReview(e){
        let con = e.currentTarget.dataset.con
        let index = e.currentTarget.dataset.index
        let page = e.currentTarget.dataset.page
        //console.log(con, '回评详情');
        wx.setStorageSync('questionInfo', JSON.stringify(con))
        wx.removeStorageSync('screenOrientation');
        wx.redirectTo({
            url: '/pages/newreview/newreview?examId='+ con.examId+'&assignmentConfigId='+ con.assignmentConfigId+'&teacherId='+con.teacherId+'&index='+index+'&page='+page
            // url: '/pages/newmarkingdetail/newmarkingdetail?con='+ encodeURIComponent(JSON.stringify(con)),
        })
    },
    // goReview(e) {
    //     let con = e.currentTarget.dataset.con;
    //     // //console.log(con, '回评详情');
    //     wx.setStorageSync('questionInfo', JSON.stringify(con))
    //     wx.removeStorageSync('screenOrientation');
    //     // //console.log('当前页面栈长度：', getCurrentPages().length);
    //     wx.navigateTo({
    //         url: `/pages/newreview/newreview?examId=${con.examId}&assignmentConfigId=${con.assignmentConfigId}&teacherId=${con.teacherId}`,
    //     });
    // },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let pages = getCurrentPages();
        let currPage = pages[pages.length - 1];
        //当前页的options，啥意思呢，就是你可能某个函数需要刷新，但是他的参数正好是传过来的参数
        //   //console.log(currPage.options); 
        // //console.info(currPage.options.flagsourceid)
        // let info = null
        // if (wx.getStorageSync('huiqongINfo')) {
        //     info = JSON.parse(wx.getStorageSync('huiqongINfo'))
        // }
        // this.getreviewlist()
        // this.getreviewlist(this.data.name,this.data.flagsourceid)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
        wx.removeStorageSync('reviewlist')
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
        wx.removeStorageSync('reviewlist')
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})